package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.CategoryReportMapper;
import com.qingcheng.pojo.order.CategoryReport;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = CategoryReportService.class)
public class CategoryReportServiceImpl implements CategoryReportService {

    @Autowired
    private CategoryReportMapper categoryReportMapper;
    /**
     * 定义查询方法
     * @param date
     * @return
     */
    @Override
    public List<CategoryReport> countCategory(LocalDate date) {

        return categoryReportMapper.countCategory(date);
    }

    /**
     * 定义更新数据库的操作
     * @param localDate
     */
    @Override
    @Transactional
    public void insertCategoryReport(LocalDate localDate) {
        //查询统计数据的集合
        List<CategoryReport> categoryReportList = categoryReportMapper.countCategory(localDate);
        //遍历集合
        if(categoryReportList!=null && categoryReportList.size()!=0){
            for (CategoryReport categoryReport : categoryReportList) {
                //定义添加CategoryReport数据的方法
                categoryReportMapper.insert(categoryReport);
            }
        }
    }

    /**
     * 定义查询指定日期区间的统计数量
     * @param date1
     * @param date2
     * @return
     */
    @Override
    public List<Map> totalCategory(String date1, String date2) {
        List<Map> maps = categoryReportMapper.totalCategory(date1, date2);
        return maps;
    }
}
